#唐门优测
#道长最帅666
""
"""
configparser库：读取ini文件
文件中由多个section构成，每个section下又有多个配置项 

section 不能重复的，里面数据通过section去查找，每个section下可以有多个key和value的键值对

"""
import os
import configparser

#创建管理对象
conf = configparser.ConfigParser()

#读取ini文件
conf.read(r'D:\daima\xin-daima\kejian\ini配置文件详解2\config.ini',encoding='utf-8')

#获取所有的section
# sections = conf.sections()
# print(sections)#返回列表
#
# items = conf.items('section0')
# print(items)#list里面对象是元组
#
# key0 = conf.get('section0','key0')
# key2 = conf.get('section1','key2')
# print(key0,key2)

"""
remove
如果想删除section中的一项，例子
"""
# sections = conf.sections()
# print(sections)#返回列表
# conf.remove_option('section0','key0')
# sections = conf.sections()
# print(sections)#返回列表
# items = conf.items('section0')
# print(items)#list里面对象是元组

"add：新增一个section"
# conf.add_section('daozhang777')
# sections = conf.sections()
# print(sections)
# "section里面新增key和value"
# conf.set('daozhang777','dao2','dao3')
# items = conf.items('daozhang777')
# print(items)

conf.write(open(r'D:\daima\xin-daima\kejian\ini配置文件详解2\config.ini','w'))

"判断"
re = conf.has_section('daozhang777')
print(re)
#追加写
conf.write(open(r'D:\daima\xin-daima\kejian\ini配置文件详解2\config.ini','a'))

#全量刷写
conf.write(open(r'D:\daima\xin-daima\kejian\ini配置文件详解2\config.ini','w'))

